<?php
/**
 * Created by 项目.
 * User: xuguopeng
 * Date: 7/14/21
 * Time: 11:06 PM
 */

namespace app\api\controller\v1;


use app\api\controller\BaseController;
use app\api\model\GfActivity as GfActivityModel;
use app\api\service\activity_order\CreateGfOrder;

class GfActivity extends BaseController
{
    protected $beforeActionList = [
        'checkExclusiveScope' => ['only' => 'getDataList']
    ];


    /**
     * 获取商家活动列表
     */
    public function getDataList($page,$limit)
    {
        $time = time();
        $query = GfActivityModel::where('end_time','gt',$time)->with('imgs.img')->order('order_sort desc');
        $count = $query->count();
        $result = $query->page($page, $limit)->select()->toArray();
        $data['count'] = $count;
        $data['data'] = $result;
        return $data;
    }

    /**
     * 获取商家活动详情
     */
    public function getDataInfo($id)
    {
        return GfActivityModel::where('id',$id)->with('imgs.img')->find();
    }

    /**
     * 创建获取活动
     */
    public function createOrder($id)
    {
        $createOrder = new CreateGfOrder($id);
        return $createOrder->entrance();
    }
}